package org.itstack.demo.design;

import org.itstack.demo.design.impl.*;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: fanYuLe
 * @CreateTime: 2023-12-28  19:15
 * @Description: 状态处理服务
 * 这是对状态服务的统⼀控制中⼼，可以看到在构造函数中提供了所有状态和实现的具体关联，放到
 * Map数据结构中。
 * 同时提供了不同名称的接⼝操作类，让外部调⽤⽅可以更加容易的使⽤此项功能接⼝，⽽不需要像
 * 在 itstack-demo-design-19-01 例⼦中还得传两个状态来判断
 */
public class StateHandler {
    private Map<Enum<Status>,State> stateMap = new ConcurrentHashMap<>();

    public StateHandler(){
        stateMap.put(Status.Check,new CheckState());         // 待审核
        stateMap.put(Status.Close, new CloseState());     // 已关闭
        stateMap.put(Status.Doing, new DoingState());     // 活动中
        stateMap.put(Status.Editing, new EditingState()); // 编辑中
        stateMap.put(Status.Open, new OpenState());       // 已开启
        stateMap.put(Status.Pass, new PassState());       // 审核通过
        stateMap.put(Status.Refuse, new RefuseState());   // 审核拒绝
    }

    public Result arraignment(String activityId,Enum<Status> currentStatus){
        return stateMap.get(currentStatus).arraignment(activityId,currentStatus);
    }
    public Result checkPass(String activityId, Enum<Status> currentStatus) {
        return stateMap.get(currentStatus).checkPass(activityId, currentStatus);
    }

    public Result checkRefuse(String activityId, Enum<Status> currentStatus) {
        return stateMap.get(currentStatus).checkRefuse(activityId, currentStatus);
    }

    public Result checkRevoke(String activityId, Enum<Status> currentStatus) {
        return stateMap.get(currentStatus).checkRevoke(activityId, currentStatus);
    }

    public Result close(String activityId, Enum<Status> currentStatus) {
        return stateMap.get(currentStatus).close(activityId, currentStatus);
    }

    public Result open(String activityId, Enum<Status> currentStatus) {
        return stateMap.get(currentStatus).open(activityId, currentStatus);
    }

    public Result doing(String activityId, Enum<Status> currentStatus) {
        return stateMap.get(currentStatus).doing(activityId, currentStatus);
    }
}
